<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: view.tpl 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>
<?php 
	$this->headLink()
  ->appendStylesheet($this->seaddonsBaseUrl()
    . '/application/modules/Sitepagealbum/externals/styles/style_sitepagealbum.css');
	$this->headScript()
	->appendFile($this->seaddonsBaseUrl() . '/application/modules/Sitepage/externals/scripts/core.js');
?>
<?php if(!$this->showLightBox || !empty($this->tab_selected_id)):?>
<?php
  $this->headScript()
    ->appendFile($this->seaddonsBaseUrl() . '/externals/moolasso/Lasso.js')
    ->appendFile($this->seaddonsBaseUrl() . '/externals/moolasso/Lasso.Crop.js')
    ->appendFile($this->seaddonsBaseUrl().'/externals/autocompleter/Observer.js')
    ->appendFile($this->seaddonsBaseUrl().'/externals/autocompleter/Autocompleter.js')
    ->appendFile($this->seaddonsBaseUrl().'/externals/autocompleter/Autocompleter.Local.js')
    ->appendFile($this->seaddonsBaseUrl().'/externals/autocompleter/Autocompleter.Request.js')
    ->appendFile($this->seaddonsBaseUrl() . '/externals/tagger/tagger.js');
  $this->headTranslate(array(
    'Save', 'Cancel', 'delete',
  ));
?>
<?php endif; ?>

<?php $album_title = $this->htmlLink(array(  'route' => 'sitepage_albumphoto_general', 'album_id' => $this->album->album_id, 'page_id' => $this->sitepage->page_id, 'tab' => $this->tab_selected_id), $this->translate($this->album->getTitle())) ?>
<?php if(!$this->showLightBox || !empty($this->tab_selected_id)):?>
<?php if(empty($this->isajax)): ?>	
	<div class="sitepage_viewpages_head">
		<?php echo $this->htmlLink(array('route' => 'sitepage_entry_view', 'page_url' => Engine_Api::_()->sitepage()->getPageUrl($this->sitepage->page_id)), $this->itemPhoto($this->sitepage, 'thumb.icon', '' , array('align'=>'left'))) ?> 
		<h2>
		  <?php $link =  $this->htmlLink(array( 'route' => 'sitepage_entry_view', 'page_url' => Engine_Api::_()->sitepage()->getPageUrl($this->sitepage->page_id), 'tab' => $this->tab_selected_id), $this->translate('Albums')) ?>
		  <?php echo $this->translate('%1$s  &raquo; ' .  $link . ' &raquo;  %2$s',
		    $this->sitepage->__toString(),
		    
		  $this->album->__toString()); ?>
		</h2>
	</div>	
	<div class='sitepage_photo_view'>
	  <div class="sitepage_photo_nav">
    	<div id= 'photo_navigation1'>
	      <?php
	      echo $this->translate('Photo %1$s of %2$s in %3$s',
	              $this->locale()->toNumber($this->image->getCollectionIndex() + 1),
	              $this->locale()->toNumber($this->album->count()),(string) $this->album->getTitle())
	      ?>
    	</div>
    	<?php if ($this->album->count() > 1): ?>
        <div id='image_next_div1' style="display:block;">
		      <a href="javascript:void(0);" onclick="photopagination('<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getPrevCollectible()) ?><?php echo "/tab/$this->tab_selected_id"?>')">
		        <?php echo $this->translate('Prev');?>
		      </a>
					<a href="javascript:void(0);" onclick="photopagination('<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible()) ?><?php echo "/tab/$this->tab_selected_id"?>')">
		        <?php echo $this->translate('Next');?>
		      </a>
	      </div>
    	<?php endif; ?>
    </div>
  <div id='image_div'>      
<?php endif; ?>   

<div class='sitepage_photo_info'> 
<div id='photo_navigation2' style="display:none;">
<?php
echo $this->translate('Photo %1$s of %2$s in %3$s',
        $this->locale()->toNumber($this->image->getCollectionIndex() + 1),
        $this->locale()->toNumber($this->album->count()),(string) $this->album->getTitle())
?>
</div>
<?php if ($this->album->count() > 1): ?>
  <div id='image_next_div2' style="display:none;">  
    <a href="javascript:void(0);" onclick="photopagination('<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getPrevCollectible()) ?><?php echo "/tab/$this->tab_selected_id"?>' )">
      <?php echo $this->translate('Prev');?>
    </a>
		<a href="javascript:void(0);" onclick="photopagination('<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible()) ?><?php echo "/tab/$this->tab_selected_id"?>')">
      <?php echo $this->translate('Next');?>
    </a>
  </div>
<?php endif; ?>
<div class='sitepage_photo_container' id='media_image_div'>
  <a id='media_image_next' <?php if($this->album->count()>1):?> onclick="photopagination('<?php echo $this->escape(Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible())) ?><?php echo "/tab/$this->tab_selected_id"?>')" <?php endif; ?> title="<?php echo $this->image->getTitle();?>">
    <?php
    echo $this->htmlImage($this->image->getPhotoUrl(), $this->image->getTitle(), array(
        'id' => 'media_image'
    ));
    ?>
  </a>
</div>
<br />
<?php if( $this->canEdit ): ?>
<div class="page_photo_right_options fright">
    <a class="icon_sitepage_photos_rotate_ccw" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.rotate(<?php echo $this->image->getIdentity() ?>, 90).addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_rotate_ccw') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Rotate Left"); ?>" ></a>

    <a class="icon_sitepage_photos_rotate_cw" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.rotate(<?php echo $this->image->getIdentity() ?>, 270).addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_rotate_cw') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Rotate Right"); ?>" ></a>

    <a class="icon_sitepage_photos_flip_horizontal" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.flip(<?php echo $this->image->getIdentity() ?>, 'horizontal').addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_flip_horizontal') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Flip Vertical"); ?>" ></a>

    <a class="icon_sitepage_photos_flip_vertical" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.flip(<?php echo $this->image->getIdentity() ?>, 'vertical').addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_flip_vertical') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Flip Horizontal"); ?>"></a>
     <input type="hidden" id='canReload' />
</div>
<?php endif ?>
<div style="overflow:hidden;">
	<?php if ($this->image->getTitle()): ?>
	  <div class="sitepage_photo_title">
	  <?php echo $this->image->getTitle(); ?>
	  </div>
	<?php endif; ?>
	<?php if ($this->image->getDescription()): ?>
	  <div class="sitepage_photo_description">
	  <?php echo $this->image->getDescription() ?>
	  </div>
	<?php endif; ?>
	<div class="sitepage_photo_tags" id="media_tags" style="display: none;">
	<?php echo $this->translate('In this photo:'); ?>
	</div>
	<div class="sitepage_photo_date">
	 <?php echo $this->translate('Added'); ?> <?php echo $this->timestamp($this->image->modified_date) ?>
	  <?php if($this->canTag): ?>
			- <a href='javascript:void(0);' onclick='taggerInstance.begin();'><?php echo $this->translate('Tag This Photo');?></a>	
		<?php endif; ?>
		<?php $editurl = $this->url(array('action' => 'photo-edit','photo_id' => $this->image->getIdentity(), 'album_id' => $this->album_id, 'page_id' => $this->sitepage->page_id, 'tab' => $this->tab_selected_id), 'sitepage_imagephoto_specific', true);?>
		<?php $removeurl = $this->url(array('action' => 'remove','photo_id' => $this->image->getIdentity(), 'album_id' => $this->album_id, 'page_id' => $this->sitepage->page_id, 'tab' => $this->tab_selected_id), 'sitepage_imagephoto_specific', true);?>
		<?php if($this->canEdit): ?>

		- <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'edit', '<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>', '<?php echo $editurl ?>');">
	    		<?php echo $this->translate('Edit');?>
	      </a>
		<?php endif; ?>    
		<?php if($this->canDelete): ?>
			- <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'delete', '<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>', '<?php echo $removeurl;?>');">
	    		<?php echo $this->translate('Delete');?>
	      </a>    				
		<?php endif; ?>
	  <?php if (!$this->message_view): ?>
		  <?php if ($this->share): ?>
	        - 
	      <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'share', '<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>');">
	    		<?php echo $this->translate('Share');?>
	      </a>  
	 		<?php endif; ?>
			<?php if ($this->report): ?>
	          - 
	      <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'report','<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>');">
	    		<?php echo $this->translate('Report');?>
	      </a>
	    <?php endif; ?>   
	         -
				<a href="<?php echo $this->url(array('module' => 'sitepage', 'controller' => 'photo', 'action' => 'download'), 'default', true); ?><?php echo '?path=' . urlencode($this->image->getPhotoUrl()) ?>" target='downloadframe' ><?php echo $this->translate('Download')?></a>
	<?php endif; ?>
	<?php if($this->canEdit): ?>
								-
				<a href="javascript:void(0);" onclick="showsmoothbox('<?php echo $this->url(array('module' => 'sitepage', 'controller' => 'photo', 'action' => 'make-page-profile-photo', 'photo' => $this->image->getGuid(), 'page_id' => $this->sitepage->page_id,'format' => 'smoothbox'), 'sitepage_imagephoto_specific', true); ?>', 'profilephoto');">
	    		<?php echo $this->translate('Make Page Profile Photo');?>
	      </a>
		<?php endif; ?> 
	</div>
</div>
</div><br />		

<?php if($this->can_comment): ?>
<?php  echo $this->action("list", "comment", "core", array("type" => "sitepage_photo", "id" => $this->image->getIdentity())) ?>
<?php endif; ?>

<?php if(empty($this->isajax)): ?>
	</div>
</div>
<?php endif; ?>

<!--Lighbox code start from here-->
<?php else: ?>
 <div>
   <?php if(empty($this->isajax)): ?>    	
       <div class="page_lightbox_options">
          <a href = "javascript:void(0)" onclick = "closeLightBox();" class="close" title="<?php echo $this->translate('Close');?>" ></a>
       </div>      
      <div id="ads_hidden" style="display: none;" >
        <?php echo $this->content()->renderWidget("sitepage.photolightbox-ads", array('limit' => 1,'tab'=>"ads_lightbox")) ?>
       </div>
   <div id='image_div'>
<?php endif; ?>
   <?php if($this->album->count()>1):?>
   <div  class="page_lightbox_options" id="page_photo_scroll">
     <a href="javascript:void(0);" onclick="photopagination('<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getPrevCollectible()) ?>' )" class="pre" title="<?php echo $this->translate('Previous');?>" ></a>
		<a href="javascript:void(0);" onclick="photopagination('<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible()) ?>')" class="nxt" title="<?php echo $this->translate('Next');?>" ></a>
  </div>
  <?php endif; ?>
	<div class="lightbox_photo_detail" id="lightbox_photo_detail">
		<?php
		echo $this->translate((string)$this->htmlLink(array('route' => 'sitepage_albumphoto_general', 'action' => 'view-album','page_id' => $this->sitepage->page_id, 'slug' => $this->album->getSlug(),'tab' => $this->tab_selected_id), $this->translate("Photos  of ").$this->sitepage->getTitle()). $this->translate(" in ").(string) $this->htmlLink(array( 'route' => 'sitepage_albumphoto_general', 'page_id' => $this->sitepage->page_id, 'album_id' => $this->album->album_id, 'slug' => $this->album->getSlug()), $this->album->__toString()));
		?>
		|
		 <?php
      echo $this->translate('Photo %1$s of %2$s',
      $this->locale()->toNumber($this->image->getCollectionIndex() + 1),
      $this->locale()->toNumber($this->album->count()));
    	?>
	</div>
  <div class="page_image_content" >
  	<div id='media_image_div'>
	  
      <a id='media_image_next'   <?php if($this->album->count()>1):?> onclick="photopagination('<?php echo $this->escape(Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible())) ?>')" <?php endif; ?> title="<?php echo $this->image->getTitle();?>">
	    <?php
	    echo $this->htmlImage($this->image->getPhotoUrl(), $this->image->getTitle(), array(
	        'id' => 'media_image',
	         'class'=>"lightbox_photo"
	    ));
	    ?>
	  </a>
	  </div>
  </div>
  
    <?php if($this->can_comment): ?>
     <div class="page_lightbox_user_options" id="page_lightbox_user_options">
       <?php if( $this->subject()->likes()->isLike($this->viewer()) ): ?>
    <a id="page_like" style="display: none;" onclick="pageLike()" href="javascript:void(0);" class="sitepage_lightbox_like" title="<?php echo $this->translate('Like This');?>"><?php echo $this->translate('Like');?></a>
      <a id="page_unlike" onclick="pageUnlike()" href="javascript:void(0);" class="sitepage_lightbox_unlike" title="<?php echo $this->translate('Unlike This');?>"><?php echo $this->translate('Unlike');?></a>
       <?php else: ?>
      <a id="page_like"   onclick="pageLike()" href="javascript:void(0);" class="sitepage_lightbox_like" title="<?php echo $this->translate('Like This');?>"><?php echo $this->translate('Like');?></a>
      <a id="page_unlike" style="display:none;" onclick="pageUnlike()" href="javascript:void(0);" class="sitepage_lightbox_unlike" title="<?php echo $this->translate('Unlike This');?>"><?php echo $this->translate('Unlike');?></a>
      <?php endif; ?>
      <a href="javascript:void(0);" onclick="$('comment-form').style.display = '';$('comment-form').body.focus();" class="sitepage_lightbox_comment" title="<?php echo $this->translate('Comments');?>" ><?php echo $this->translate('Comments');?></a>
    </div>
   <?php endif; ?>
  
     <?php if( $this->canEdit ): ?>
      <div class="page_lightbox_user_right_options" id="page_lightbox_user_right_options">
        <a class="icon_sitepage_photos_rotate_ccw" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.rotate(<?php echo $this->image->getIdentity() ?>, 90).addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_rotate_ccw') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Rotate Left"); ?>" ></a>
        
        <a class="icon_sitepage_photos_rotate_cw" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.rotate(<?php echo $this->image->getIdentity() ?>, 270).addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_rotate_cw') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Rotate Right"); ?>" ></a>
        
        <a class="icon_sitepage_photos_flip_horizontal" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.flip(<?php echo $this->image->getIdentity() ?>, 'horizontal').addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_flip_horizontal') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Flip Vertical"); ?>" ></a>
        
        <a class="icon_sitepage_photos_flip_vertical" href="javascript:void(0)" onclick="$(this).set('class', 'icon_loading');en4.sitepage.flip(<?php echo $this->image->getIdentity() ?>, 'vertical').addEvent('complete', function(){ this.set('class', 'icon_sitepage_photos_flip_vertical') }.bind(this)); loadingImage();" title="<?php echo $this->translate("Flip Horizontal"); ?>"></a>
       
      </div>
      <?php endif ?>
   
  <div class="page_photo_lightbox_content" >
    <div id="page_lightbox_text">
      <div class="page_photo_lightbox_content_left">
				<div class="photo_detail">
	        <span class="owner">
	         <?php
	          echo $this->translate('By %1$s',
	          $this->htmlLink($this->image->getOwner()->getHref(),$this->image->getOwner()->getTitle()));
	        	?>
	        	| <?php echo $this->timestamp($this->image->modified_date) ?>
	        </span>
	      </div>
	      
	      <div class="photo_options">
	        <?php if($this->canTag): ?>
	        	<a href='javascript:void(0);' onclick='taggerInstance.begin();' class="buttonlink sitepage_photo_tag"><?php echo $this->translate('Tag This Photo');?></a>
	        <?php endif; ?>
         	<?php if (!$this->message_view): ?>
            <?php if ($this->share): ?>
              <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'share', '<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>');" class="icon_sitepages_share buttonlink">
                <?php echo $this->translate('Share');?>
              </a>
            <?php endif; ?>
            <?php if ($this->report): ?>
              <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'report','<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>');" class="icon_sitepages_report  buttonlink">
              	<?php echo $this->translate('Report');?>
              </a>
            <?php endif; ?>
          <?php endif; ?>
          <?php if($this->canEdit): ?>
						<a href="javascript:void(0);" onclick="showsmoothbox('<?php echo $this->url(array('module' => 'sitepage', 'controller' => 'photo', 'action' => 'make-page-profile-photo', 'photo' => $this->image->getGuid(), 'page_id' => $this->sitepage->page_id,'format' => 'smoothbox'), 'sitepage_imagephoto_specific', true); ?>', 'profilephoto');" class=" buttonlink sitepage_photo_profile">
			    		<?php echo $this->translate('Make Page Profile Photo');?>
			      </a>
					<?php endif; ?> 
          <a href="<?php echo $this->url(array('module' => 'sitepage', 'controller' => 'photo', 'action' => 'download'), 'default', true); ?><?php echo '?path=' . urlencode($this->image->getPhotoUrl()) ?>" target='downloadframe' class="buttonlink sitepage_lightbox_photos_download"><?php echo $this->translate('Download')?></a>
          
          <?php if($this->canDelete): ?>
          <?php $removeurl = $this->url(array('action' => 'remove','photo_id' => $this->image->getIdentity(), 'album_id' => $this->album_id, 'page_id' => $this->sitepage->page_id, 'tab' => $this->tab_selected_id), 'sitepage_imagephoto_specific', true);?>
            <a href="javascript:void(0);" onclick="showsmoothbox('<?php  echo $this->image->getGuid(); ?>', 'delete', '<?php  echo $this->image->getType() ?>', '<?php echo $this->image->getIdentity() ?>', '<?php echo $removeurl;?>');" class="sitepage_lightbox_photos_delete buttonlink">
            	<?php echo $this->translate('Delete This Photo');?>
            </a>
          <?php endif; ?>
        </div>
      </div> 
       
      <div class="page_photo_lightbox_content_middle">
        <div class="sitepage_lightbox_photo_tags" id="media_tags" style="display: none;">
          <?php echo $this->translate('In this photo:'); ?>
        </div>
        <?php if($this->canEdit  || !empty($this->image->description)  ): ?>
        <div class="sitepage_lightbox_photo_description widthfull" id="link_page_description" style="display:block;">
        	<?php if($this->canEdit): ?>
	          <span class="lightbox_photo_description_edit_icon">
	          	<a href="javascript:void(0);" onclick="showeditDescription()" title=" <?php echo $this->translate('Edit this caption');?> "></a>
	          </span>
          <?php endif; ?>
          <span id="page_description" class="lightbox_photo_description">
            <?php if (!empty($this->image->description) ): ?>
              <?php echo $this->image->getDescription() ?>
            <?php elseif($this->canEdit): ?>
              <a href="javascript:void(0);" onclick="showeditDescription()" >  <?php echo $this->translate('Add a caption');?> </a>
            <?php endif; ?>
          </span>
        </div>
	       <?php endif; ?> 
        <div class="sitepage_lightbox_photo_description" id="edit_page_description" style="display: none;">
           <textarea rows="2" cols="10"  name="edit_description" id="editor_page_description" title="<?php echo $this->translate('Add a caption');?>" ><?php echo $this->image->description; ?></textarea>
	        <div>
	          <button name="save" onclick="saveeditDescription()"><?php echo $this->translate('Save'); ?></button>
	          <button name="cancel" onclick="showeditDescription();"><?php echo $this->translate('Cancel'); ?></button>
	        </div>
	        <div id="page_description_loading" style="display: none;">
	          <center><img src="application/modules/Sitepage/externals/images/loader.gif" /></center>
	        </div>
	      </div> 

        <?php if($this->can_comment): ?>
					<div id="photo_view_comment" >
          <?php  echo $this->action("list", "comment", "core", array("type" => "sitepage_photo", "id" => $this->image->getIdentity())) ?>
					</div>
        <?php endif; ?>
        
      </div>
      
	    <div class="fright" id="ads">  
	  
     	</div>
   	</div>
 	</div>

 <?php if(empty($this->isajax)): ?>
 </div>
<?php endif; ?>

 </div>
<script type="text/javascript">
  function pageLike(){
 
    en4.core.comments.like('<?php echo $this->subject()->getType()?>', '<?php echo $this->subject()->getIdentity() ?>')
    document.getElementById('page_like').style.display="none";
    document.getElementById('page_unlike').style.display="";
  }
  
  function pageUnlike(){
    en4.core.comments.unlike('<?php echo $this->subject()->getType()?>', '<?php echo $this->subject()->getIdentity() ?>');
    document.getElementById('page_like').style.display="";
    document.getElementById('page_unlike').style.display="none";
  }

  function showeditDescription(){
    if(document.getElementById('edit_page_description')){
      if(document.getElementById('link_page_description').style.display=="block"){
      document.getElementById('link_page_description').style.display="none";
      document.getElementById('edit_page_description').style.display="block";
      $('editor_page_description').focus();
      }else{
      document.getElementById('link_page_description').style.display="block";
      document.getElementById('edit_page_description').style.display="none";
      }

      if(document.getElementById('page_description_loading'))
      document.getElementById('page_description_loading').style.display="none";
    }
  }

  function saveeditDescription()
  {
    var photo_id = '<?php echo $this->image->getIdentity(); ?>';
    var str =document.getElementById('editor_page_description').value.replace('/\n/g','<br />');
    var str_temp =document.getElementById('editor_page_description').value;
    
    document.getElementById('page_description_loading').style.display="block";
    document.getElementById('edit_page_description').style.display="none";
      en4.core.request.send(new Request.HTML({
        url :'<?php echo $this->url(array('module' => 'sitepage', 'controller' => 'photo', 'action' => 'edit-description'), 'default', true) ?>',
        data : {
          format : 'html',
          text_string : str_temp,
          photo_id : photo_id
        },
        onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {
          
          if(str=='')
           str_temp='<a href="javascript:void(0);" onclick="showeditDescription()" >  <?php echo $this->string()->escapeJavascript($this->translate('Add a caption'));?> </a>';
         document.getElementById('page_description').innerHTML=str_temp;
         showeditDescription();

        }
      }));
  }

</script>
<?php endif; ?>

<script type="text/javascript">

 <?php if(!$this->showLightBox || !empty($this->tab_selected_id)):?>
   var baseY = '0';
 function getPrevPhoto(){
   return '<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getPrevCollectible()) ?><?php echo "/tab/$this->tab_selected_id"?>';
 }
  function getNextPhoto(){
   return '<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible()) ?><?php echo "/tab/$this->tab_selected_id"?>';
 }
 <?php else: ?>
 function getPrevPhoto(){
   return '<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getPrevCollectible()) ?>';
 }
  function getNextPhoto(){
   return '<?php echo Engine_Api::_()->sitepage()->getHreflink($this->image->getNextCollectible()) ?>';
 }
 <?php endif; ?>
	<?php if($this->viewer()->getIdentity()):?>
		var taggerInstance;

		en4.core.runonce.add(function() {
//          var baseY1 = '0';
//          var divY=$('media_image_div').getPosition().y;
//          var imgY=$('media_image').getPosition().y;
//          baseY1=imgY-divY;
        taggerInstance = new Tagger('media_image_next', {
				'title' : '<?php echo $this->translate('Tag This Photo');?>',
				'description' : '<?php echo $this->translate('Type a tag or select a name from the list.');?>',
				'createRequestOptions' : {
					'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'add'), 'default', true) ?>',
					'data' : {
						'subject' : '<?php echo $this->subject()->getGuid() ?>'
					}
				},
				'deleteRequestOptions' : {
					'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'remove'), 'default', true) ?>',
					'data' : {
						'subject' : '<?php echo $this->subject()->getGuid() ?>'
					}
				},
				'cropOptions' : {
					'container' : $('media_image_next')
				},
				'tagListElement' : 'media_tags',
				'existingTags' : <?php echo $this->action('retrieve', 'tag', 'core', array('sendNow' => false)) ?>,
				'suggestParam' : <?php echo $this->action('suggest', 'friends', 'user', array('sendNow' => false, 'includeSelf' => true)) ?>,
				'guid' : <?php echo ( $this->viewer()->getIdentity() ? "'".$this->viewer()->getGuid()."'" : 'false' ) ?>,
				'enableCreate' : <?php echo ( $this->canTag ? 'true' : 'false') ?>,
				'enableDelete' : <?php echo ( $this->canUntagGlobal ? 'true' : 'false') ?>
       // 'baseY':baseY1
			});
      // Remove the onclick attrib while tagging
			var onclickNext = $('media_image_next').getProperty('onclick');
			taggerInstance.addEvents({
				'onBegin' : function() { 
				$('media_image_next').setProperty('onclick','');
				},
				'onEnd' : function() {
				$('media_image_next').setProperty('onclick',onclickNext);
				}
			});



		});

	<?php endif;?>

 window.addEvent('keyup', function(e) { 
    if( e.target.get('tag') == 'html' || e.target.get('tag') == 'a'||
        e.target.get('tag') == 'body' ) {
      if( e.key == 'right' ) {
        photopagination(getNextPhoto());
      } else if( e.key == 'left' ) {
        photopagination(getPrevPhoto());
      }
    }
  });


  var loadingImage= function(){
     if(document.getElementById('media_image_div'))
		$('media_image').src = "application/modules/Sitepage/externals/images/loader.gif";
		<?php if($this->showLightBox && empty($this->tab_selected_id)):?>
      $('media_image').style.marginTop='245px';
    <?php endif;?>
  };

	var photopagination = function(url)
	{       if($('ads') && $('ads_hidden')){
            $('ads_hidden').innerHTML = $('ads').innerHTML;
          }

		<?php if($this->showLightBox && empty($this->tab_selected_id)):?>

        if(document.getElementById('lightbox_photo_detail'))
         document.getElementById('lightbox_photo_detail').style.display="none";
           setHtmlScroll("auto");
           setImageScroll("hidden");
        if(document.getElementById('media_image_div'))
       document.getElementById('media_image_div').innerHTML="<img src='application/modules/Sitepage/externals/images/loader.gif'  class='lightbox_loader_img' />";
         
        if(document.getElementById('page_lightbox_text'))
        document.getElementById('page_lightbox_text').style.display="none";
        if(document.getElementById('page_lightbox_user_options'))
        document.getElementById('page_lightbox_user_options').style.display="none";
         if(document.getElementById('page_lightbox_user_right_options'))
        document.getElementById('page_lightbox_user_right_options').style.display="none";
     <?php else: ?>
       if(document.getElementById('media_image_div'))
       document.getElementById('media_image_div').innerHTML="<img src='application/modules/Sitepage/externals/images/loader.gif' />";
    <?php endif; ?>
    en4.core.request.send(new Request.HTML({
			url : url,
			data : {
				format : 'html',
				isajax : 1
			},
			onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {

				$('image_div').innerHTML = responseHTML;      
        <?php if(!$this->showLightBox || !empty($this->tab_selected_id)):?>
         if($('photo_navigation1'))
				$('photo_navigation1').innerHTML = $('photo_navigation2').innerHTML;

				if($('image_next_div2')) {
					$('image_next_div1').innerHTML = $('image_next_div2').innerHTML;
				}   
        <?php else: ?>
           setHtmlScroll("hidden");
           setImageScroll("auto");
           if($('ads') && $('ads_hidden')){
            $('ads').innerHTML =  $('ads_hidden').innerHTML;
            $('ads_hidden').innerHTML='';
           }
            
        <?php endif; ?>

			}
		}));
	};

	function showsmoothbox(photo_id, action, type, id, url)
	{
		var page_id = "<?php echo $this->sitepage->page_id; ?>";
		var album_id = "<?php echo $this->album_id; ?>";
		var tab = "<?php echo $this->tab_selected_id; ?>";

		//var photo_id = "<?php //$this->image->getGuid(); ?>";
		if(action == 'profilephoto') {
			var url = photo_id;
			Smoothbox.open(url);
			parent.Smoothbox.close;
		}
		else if(action == 'report') {
			Smoothbox.open(en4.core.baseUrl+'core/report/create/subject/' + photo_id + '/tab/' + tab + '/format/smoothbox');
			parent.Smoothbox.close;
		}
		else if(action == 'share') {
			Smoothbox.open(en4.core.baseUrl+ 'activity/index/share/type/' + type + '/id/' + id + '/tab/' + tab + '/format/smoothbox');
			parent.Smoothbox.close;
		}
		else if(action == 'edit') {
			Smoothbox.open(url);
			parent.Smoothbox.close;
		}
		else if(action == 'delete') {
			Smoothbox.open(url);
			parent.Smoothbox.close;
		}
	};
</script>